﻿<!DOCTYPE html >
<html>

	<head>
		<meta name="Generator" content="tpshop" />
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width">
		<title>手机绑定</title>
		<meta http-equiv="keywords" content="用户注册-{$web_name}" />
		<meta name="description" content="用户注册-{$web_name}" />
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
		<link rel="stylesheet" type="text/css" href="/themes/wnsc_moblie/newMobile/User/login/css/public.css" />
		<link rel="stylesheet" type="text/css" href="/themes/wnsc_moblie/newMobile/User/login/css/login.css" />
		<script type="text/javascript" src="/themes/wnsc_moblie/newMobile/User/login/js/jquery.js"></script>
		<script src="/themes/wnsc_moblie/newMobile/User/login/js/global.js"></script>
		<script src="/themes/wnsc_moblie/newMobile/User/login/js/mobile_common.js"></script>
		<script type="text/javascript" src="/themes/wnsc_moblie/newMobile/User/login/js/mobile/layer.js"></script>
	</head>

	<body>
	<?php
				$agent = $_SERVER['HTTP_USER_AGENT'];
				if(strpos($agent,"Html5Plus") === false){
			?>
		<header id="header" class='header'>
			<div class="h-left">
				<a href="{:U('user/bduser')}" class="back"></a>
			</div>
			<div class="h-mid">手机绑定</div>
		</header>
	<?php
	}
			?>
		<div id="tbh5v0">
			<div class="log_reg_box">
				<!--<ul class="tab" id="logRegTab">
			<li id="mob_log" class="curr" onClick="changeForm(this)">
				<span>
					<font>手机注册</font>
				</span>
			</li>
			<li id="email_log" class="curr currr" onClick="changeForm(this)">
				<span>
					<font>邮箱注册</font>
				</span>
			</li>
		</ul>-->
				<div id="logRegTabCon">
					<div class="log_reg_item" id="phonearea">
						<form action="" method="post" id="mobileForm">
							
							
						
							<div class="field phone">
								<input type="text" id="username" name="username" placeholder="手机号" class="c-form-txt-normal" onBlur="checkMobilePhone(this.value);" />
								<div class="tips">
									<span id="mobile_phone_notice"></span>
								</div>
							</div>
							<div class="field pwd">
								<input type="password" id="password" name="password" placeholder="密码" class="c-form-txt-normal" onBlur="check_password(this.value);" />
								<div class="tips">
									<span id="password_notice"></span>
								</div>
							</div>
							<div class="field pwd">
								<input type="password" id="password2" name="password2" placeholder="确认密码" class="c-form-txt-normal" onBlur="check_confirm_password(this.value);" />
								<div class="tips">
									<span id="confirm_password_notice"></span>
								</div>
							</div>
							<div class="yanzheng" style=" margin-top:0px;">
								<div class="codeTxt">
									<input type="text" id="mobile_code" name="mobile_code" placeholder="手机验证码" />
								</div>
								<div class="codePhoto">
									<input id="zphone" type="button" rel="mobile" value="获取手机验证码 " onClick="sendcode(this)" class="zphone" style=" color:#FFF">
								</div>
							</div> <input type="button" id="btn_submit"  class="btn_big1" value="绑定" />
						</form>
					</div>

				</div>
			</div>
		</div>
		<script type="text/javascript">
			setCurrentForm($("#mobileForm"));
			var flag = false;

			function changeForm(obj) {
				$(obj).removeClass('currr');
				$(obj).siblings().addClass('currr');
				if($(obj).attr('id') == 'mob_log') {
					$('#phonearea').show();
					setCurrentForm($("#mobileForm"))
					$('#emailarea').hide();
				} else {
					$('#phonearea').hide();
					setCurrentForm($("#emailForm"))
					$('#emailarea').show();
				}
			}

			function setCurrentForm(formObj) {
				currentForm = $(formObj);
			}

		

			function checkMobilePhone(mobile) {
				if(mobile == '') {
					$('#mobile_phone_notice').css('color', 'red');
					$('#mobile_phone_notice').html('* 手机号码不能为空');
					flag = false;
				} else if(checkMobile(mobile)) {

					$.ajax({
						type: "GET",
						url: "/user/register_validate2", //+tab,
						data: {
							mobile: mobile
						}, 
						success: function(data) {
							if(data.code == '0') {
								$('#mobile_phone_notice').css('color', 'green');
								$('#mobile_phone_notice').html('* 可以绑定');
								flag = true;
							} 
							
							if(data.code == '1') {
								$('#mobile_phone_notice').css('color', 'green');
								$('#mobile_phone_notice').html('* 手机号已存在,绑定后两者将合并');
								flag = true;
							}
							 
						}
					});
				} else {
					$('#mobile_phone_notice').css('color', 'red');
					$('#mobile_phone_notice').html('* 手机号码格式不正确');
					flag = false;
				}
			}

			function check_password(password) {
				if(password.indexOf(" ") != -1) {
					$(currentForm).find('#password_notice').css('color', 'red').html("登录密码不能包含空格");
					flag = false;
				} else if(password.length < 6) {
					$(currentForm).find('#password_notice').css('color', 'red').html('- 登录密码不能少于 6 个字符。');
					flag = false;
				} else {
					$(currentForm).find('#password_notice').css('color', 'green').html('可以绑定');
					flag = true;
				}
			}

			function check_confirm_password(confirm_password) {
				var password = $(currentForm).find('#password').val();
				if(password.indexOf(" ") != -1) {
					$(currentForm).find('#confirm_password_notice').css('color', 'red').html("确认密码不能包含空格");
					flag = false;
					return false;
				}
				if(confirm_password.length < 6) {
					$(currentForm).find('#confirm_password_notice').css('color', 'red').html('- 登录密码不能少于 6 个字符。');
					flag = false;
					return false;
				}
				if(confirm_password != password) {
					$(currentForm).find('#confirm_password_notice').css('color', 'red').html('两次密码不一致');
					flag = false;
				} else {
					$(currentForm).find('#confirm_password_notice').css('color', 'green').html('可以绑定');
					flag = true;
				}
			}
			$(function(){
				$('#btn_submit').click(function(){
					var username = $.trim($(currentForm).find('#username').val());
					var password = $(currentForm).find('#password').val();
					var password2 = $(currentForm).find('#password2').val();
					var mobile_code = $(currentForm).find('#mobile_code').val();
					if(username.length > 0 && password.length > 0 && password2.length > 0 && flag) {
					$.ajax({
						url: '/user/phone_bd',
						type: 'post',
						dataType: 'json',
						data: {
							mobile: username,
							password: password,
							sms_captcha: mobile_code,
						},
						success: function(result) {
							if(result.code==0){
								layer.open({
									content: result.msg,
									time: 1
								});
							}
							if(result.code==1){
								layer.open({
									content: result.msg,
									time: 1
								});
								setTimeout('location.href="/user/bduser.html";',1500)
							}
						}
					})
						
					} else {
						return false;
					}
				})
			})
			

			function sendcode(o) {
				if(flag) {
					$.ajax({
						url: '/user/sms_captcha2',
						type: 'post',
						dataType: 'json',
						data: {
							type: $(o).attr('rel'),
							send: $.trim($(currentForm).find('#username').val()),
							scene: 1
						},
						success: function(res) {
							console.log(res)
							if(res.code == 0) {
								layer.open({
									content: res.message,
									time: 1
								});
								countdown(o);
							} else {
								layer.open({
									content: res.message,
									time: 2
								});
							}
						}
					})
				}
			}

			var wait = 150;

			function countdown(obj, msg) {
				obj = $(obj);
				if(wait == 0) {
					obj.removeAttr("disabled");
					obj.val(msg);
					wait = 150;
				} else {
					if(msg == undefined || msg == null) {
						msg = obj.val();
					}
					obj.attr("disabled", "disabled");
					obj.val(wait + "秒后重新获取");
					wait--;
					setTimeout(function() {
						countdown(obj, msg)
					}, 1000)
				}
			}
		</script>
	</body>

</html>